import re

import requests
# url = 'https://wallpaperscraft.com/catalog/art'
url = 'https://wallpaperscraft.com'
url2 ='https://wallpaperscraft.com/all/page2'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
# print(response.text)
href = re.findall('<a class="wallpapers__link" href="(.*?)"',response.text)
print(href)

for link in href:


    html_data = requests.get(url= 'https://wallpaperscraft.com/'+link,headers=headers).text
    # print(html_data)
    img_info = re.findall('<img class="wallpaper__image" src="(.*?)" alt="(.*?)"', html_data)
    name = re.findall('<img class="wallpaper__image" src="(.*?)" ', html_data)


    img_content = requests.get(url=img_info[0][0],headers=headers).content
    with open('img\\' + img_info[0][1] + '.jpg', mode='wb') as f:
            print("%s 已下载成功",name)
            f.write(img_content)